<div class="box"> <!-- Box begins here -->
	<h2>Chỉnh sửa thông tin</h2>
	<!--
	Standard form within a fieldset tag;
-->
	<?php 
		$error = $this->error;
		$data = $this->data;
	?>
	<form method="post" action="" enctype="multipart/form-data"><!-- Form -->
				<?php 
					if(isset($this->success)){
						echo "<div class='success'><center><h3>".$this->success."</h3></center></div>";					
					}
				?>
					<fieldset><legend>Thông tin đăng nhập</legend>
					<div class="input_field">
						<label for="email">Email đăng nhập</label>
 												
 						<?php echo $this->formText("email",$data['email'],array('readonly'=>'readonly')); ?>
 						<?php 
 							if(isset($error['email'])){
							echo '<span class="validate_error">'.$error['email'].'</span>';
							}
 						?>
					</div>
					</fieldset>
					<?php if($data['id']==$this->user_info->id) 
					{
					?>
					<fieldset><legend>Thông tin cá nhân</legend>
					<?php echo $this->formHidden('id',$data['id'],null);?>
						<div class="input_field">
						
							<label for="last_name">Tên</label>						
	 						<?php echo $this->formText("first_name",$data['first_name'],null); ?>
	 						
	 						<?php 
 							if(isset($error['first_name'])){
							echo '<span class="validate_error">'.$error['first_name'].'</span>';
							}
 							?>
	 						
						</div>
						<div class="input_field">
							<label for="middle_name">Tên lót</label>						
	 						<?php echo $this->formText("middle_name",$data['middle_name'],null); ?>
						</div>
						<div class="input_field">
							<label for="middle_name">Họ</label>						
	 						<?php echo $this->formText("last_name",$data['last_name'],null); ?>
	 						
	 						<?php 
 								if(isset($error['last_name'])){
									echo '<span class="validate_error">'.$error['last_name'].'</span>';
								}
 							?>
	 						
						</div>
						
						<div class="input_field">
							<label for="birthday">Ngày sinh nhật</label>						
	 						<?php echo $this->formText("birthday",$data['birthday'],array('readonly'=>'readonly')); ?>
						</div>
						<div class="input_field">
						<label for="image">Ảnh đại diện</label>
 						<?php 
 							if($data['image']!='')
 								echo $this->formFile("image",array("size"=>55,"disabled"=>"disabled"));
 							else
 								echo $this->formFile("image",array("size"=>55));
 						?>
 						<?php if(!empty($this->error['image'])): ?>
 						<span class="validate_error"><?php echo $this->error['image']; ?></span>
 						<?php endif; ?>
 						<div id="view_image_news">
 						<br /><img <?php if($data['image']!='') echo 'src="'.$this->baseUrl().WEBMASTER_URL.'/'.$data['image'].'"';?> width="180px"/>
 						<br />
 						<?php 
 							if($data['image']!='')
 							{
 						?>
 						<a class="img-delete" href="<?php echo $this->url(array("module"=>"administrator","controller"=>"webmaster","action"=>"removeimg","id"=>$data['id']),null,true);?>">Xóa</a>
 						<?php 
 							}
 							?>
						</div>
					</div>
						<div class="input_field">
							<label for="sex">Giới tính</label>
							
	 						<select name="sex">
	 							<option value="0">Nam</option>
	 							<option value="1" <?php if($data['sex']=='1') echo 'selected="selected"'?>>Nữ</option>
	 						</select>
						</div>
						<div class="input_field">
							<label for="phone">Số điện thoại</label>						
	 						<?php echo $this->formText("phone",$data['phone'],null); ?>
	 						<?php if(!empty($this->error['phone'])): ?>
 						<span class="validate_error"><?php echo $this->error['phone']; ?></span>
 						<?php endif; ?>
						</div>
						<div class="input_field">
							<label for="address">Địa chỉ</label>						
	 						<?php echo $this->formText("address",$data['address'],null); ?>
						</div>
						<div class="input_field">
							<label for="province">Tỉnh/Thành phố </label>
	 						<select name="province" onchange="change_district(this.options[this.selectedIndex].value);">
	 							<?php 
	 								$modelProvince = new Model_Province_Province();
	 								$province = $modelProvince->getAll();
	 								foreach ($province as $item)
	 								{
	 									if($item['id']==$data['province'])
	 									{
	 									
	 							?>
	 							<option value="<?php echo $item['id'];?>" selected="selected" ><?php echo $item['name'];?></option>
	 							<?php } else {?>
	 							<option value="<?php echo $item['id'];?>"><?php echo $item['name'];?></option>
	 							<?php } }?>
	 							
	 						</select>
 						</div>
 						<div id="input_district" class="input_field">
							<label for="district">Quận/Huyện </label>
	 						<select name="district">
	 							<?php 
	 								$modelDistrict = new Model_District_District();
	 								$district = $modelDistrict->getItemsByProvince($data['province']);
	 								foreach ($district as $item)
	 								{
	 									if($item['id']==$data['district'])
	 									{
	 									
	 							?>
	 							<option value="<?php echo $item['id'];?>" selected="selected"><?php echo $item['name'];?></option>
	 							<?php } else {?>
	 							<option value="<?php echo $item['id'];?>"><?php echo $item['name'];?></option>
	 							<?php } }?>
	 						</select>
 						</div>
					</fieldset>
					<?php 
					}
					 ?>
					<fieldset><legend>Quyền</legend>
					<div class="input_field">
						<label for="role">Quyền </label>
 						<select name="role">
 							<?php 
 								$modelRole = new Model_WebmasterRole_WebmasterRole();
 								$role = $modelRole->getAll();
 								foreach ($role as $item)
 								{
 								    if($item['id']!=$data['role'])
 								    {
 							?>
 							<option value="<?php echo $item['id'];?>"><?php echo $item['name'];?></option>
 							<?php
 								    } else {
 								    ?>
 							<option value="<?php echo $item['id'];?>" selected="selected"><?php echo $item['name'];?></option>  
 							<?php }
 								}
 							?>  
 						</select>
					</div>
					<div class="input_field">
							<label for="status">Trạng thái</label>
							<?php 
								//Các thể loại như thể loại gốc, thể loạt có chứa bài viết, có chứa thể loại con thì không thể chuyển trạng thái được
								if($data['id']!=$this->user_info->id) {
							?>
 							<?php echo $this->formRadio("status",(empty($data['status'])) ? "1" : $data['status'],null,array("1"=>"Kích hoạt","0"=>"Không kích hoạt"),null); ?>
 							<?php } else { ?>
 							<?php if($data['status']==1) {
	 							    echo '<select name="status">';
	 							    echo '<option value="1" >Kích hoạt</option>';
	 							    echo '</select>';
 								}
 								else
 								{
 								    echo '<select name="status">';
 								    echo '<option value="1" >Kích hoạt</option>';
 								    echo '</select>';
 								}
 							?>
 							<?php }?>
						</div>
					</fieldset>
					<input class="submit" type="submit" value="Lưu" />
			</form><!-- /Form -->
</div> <!-- END Box-->
<script>
function change_district(id){
	$("#input_district").load("<?php echo $this->baseUrl()?>/administrator/ajax/district/id/"+id);
}
</script>
<script>
    $(function() {
        $( "#birthday" ).datepicker({
        	changeMonth: true,
            changeYear: true,
            dateFormat: "yy-mm-dd" 
        });
    });
</script>
<script type="text/javascript">
	$(document).ready(function(){
			$(".img-delete").click(function(){
				if(confirm("Bạn muốn xóa hình ảnh ?")){
					$(this).parent().remove();
					$("#image").removeAttr("disabled");
					$.get($(this).attr("href"));
				}
				return false;
			});
	});
</script>